
class WheelObject {
    private _main: CarObject = null
    private _forceX: number = 0
    private _forceY: number = 0
    private _forceLocalPos: Box2D.Common.Math.b2Vec2 = null
    private _friction: number = 0

    constructor(main: CarObject, forceX: number, forceY: number) {
        this._main = main
        this._forceX = forceX * 1
        this._forceY = forceY * 1
        this._forceLocalPos = GameScene.GetPhyPos(this._forceX, this._forceY)
        this._friction = 1
    }

    public AddForce(force: number) {
        let fp = new Box2D.Common.Math.b2Vec2(this._main.CosBodyAngle * force, this._main.SinBodyAngle * force)

        let vx = this._main.body.GetLinearVelocityFromLocalPoint(this._forceLocalPos).x
        let vy = this._main.body.GetLinearVelocityFromLocalPoint(this._forceLocalPos).y
        let ff = new Box2D.Common.Math.b2Vec2(-this._friction * vx, -this._friction * vy)
        fp.Add(ff)

        //fp = new Box2D.Common.Math.b2Vec2(force, force)
        if (Math.abs(fp.x) > 0 || Math.abs(fp.y) > 0) {
         
            this._main.body.ApplyImpulse(fp, this._main.body.GetWorldPoint(this._forceLocalPos))
            console.debug("AddForce:(%.4f, %.4f)", fp.x, fp.y)
        }
    }
}